package ru.ncedu.java.dmsi.robots.model;

import ru.ncedu.java.dmsi.robots.actions.Action;
import ru.ncedu.java.dmsi.robots.actions.impl.MoveAction;

public class Bullet extends ActiveWorldObject {
    private Direction direction;
    private int id;
    private Point location;
    public Bullet( Point location, Direction dir ) {
        direction = dir;
        id = generateID();
        this.location = location;
    }

    @Override
    public int getId() {
        return id;
    }

    @Override
    public Point getPoint() {
        return location; // World know bullet location
    }
    public Direction getDirection() {
        return direction;
    }

    @Override
    public Action doStep(ActionContext context) {
        PointFactory pf = PointFactory.getInstance();
        Point location = context.getCurrentLocation();
        if (direction == null)
            return new MoveAction(location);
        if (direction == Direction.DOWN_DIRECTION)
            return new MoveAction(pf.getPoint(location.getX(), location.getY() - 2));
        if (direction == Direction.LEFT_DIRECTION)
            return new MoveAction(pf.getPoint(location.getX() - 2, location.getY()));
        if (direction == Direction.UP_DIRECTION)
            return new MoveAction(pf.getPoint(location.getX(), location.getY() + 2));
        // RIGHT_DIRECTION as default
        return new MoveAction(pf.getPoint(location.getX() + 2, location.getY()));
    }
    public void move( Point newLocation ) {
        location = newLocation;
    }
    @Override
    public String toString() {
        if (direction == Direction.DOWN_DIRECTION || direction == Direction.UP_DIRECTION)
            return "|";
        return "-";
    }
// Is it needed?
    //public void setLocation( Point newLocation ) {
    //    location = newLocation;
    //}
}
